<template>
	<el-dialog v-model="visible" title="收文登记" :width="500" destroy-on-close @closed="$emit('closed')">
			<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px">
			<el-form-item label="收文标题" prop="flowTitle">
				<el-input v-model="form.flowTitle" placeholder="收文标题" clearable maxlength="90"></el-input>
			</el-form-item>
				<el-form-item label="来文单位" prop="fromOrg">
					<el-select
						v-model="form.fromOrg"
						filterable
						allow-create
						default-first-option
						:filter-method="getBpmFromOrgListForSelect"
						style="width:100%"
						placeholder="请输入或选择来文单位">
						<el-option
							v-for="item in fromOrgList"
							:key="item.value"
							:label="item.value"
							:value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
			<el-row :gutter="2">
			<el-col :lg="4">
				<el-form-item label="是否关注">
					<el-checkbox v-model="form.follow" :checked="form.follow"></el-checkbox>
				</el-form-item>
			</el-col>
				<el-col :lg="10">
					<el-form-item label="密级">
						<el-select v-model="form.classifiedLevel">
							<el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			<el-col :lg="10">
				<el-form-item label="紧急程度">
					<el-select v-model="form.urgency">
						<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col>
			</el-row>
		</el-form>

		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 定</el-button>
		</template>
	</el-dialog>
</template>
<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			options:[
				{value:'0',label:'一般'},
				{value: '1',label:'紧急'},
				{value: '2',label:'加急'}
			],
			options1:[
				{value:"1",label:'普通'},
				{value:"2",label:'秘密'},
				{value:"3",label:'机密'},
				{value:"4",label:'绝密'}
			],
			fromOrgList:[],
			form:{
				flowId:'',
				flowTitle:'',
				fromOrg:'',
				classifiedLevel:'1',
				urgency:'0',
				follow:false
			},
			rules:{
				flowTitle: [
					{required: true, message: '请输入收文标题'}
				]
			}

		}
	},
	mounted() {
		this.getBpmFromOrgListForSelect('');
	},
	methods:{
		open(){
			this.visible = true;
			return this;
		},
		async getDocNumByBpmFlow(){
			var res = await this.$API.bpm.bpmFlow.getDocNumByBpmFlow.get({flowId:this.form.flowId});
			if (res.code == 200) {
				this.form.flowTitle=res.data.flowTitle;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					this.setBpmFromOrg();
					this.$nextTick(() => {
						this.$router.replace({
							path: '/doc/handle/dowork',
							query:{
								flowId:this.form.flowId,
								opType:'start',
								flowTitle:this.form.flowTitle,
								urgency:this.form.urgency,
								follow:this.form.follow,
                				isDoc:'2',
								classifiedLevel:this.form.classifiedLevel,
								fromOrg:this.form.fromOrg
							}
						})
					})
				}
			})
		},
		setData(data)
		{
			this.form.flowId = data.flowId
			this.getDocNumByBpmFlow();
		},
		async setBpmFromOrg(){
			await this.$API.bpm.bpmFromOrg.setBpmFromOrg.post({fromOrg:this.form.fromOrg,orgType:'2'});
		},
		async getBpmFromOrgListForSelect(value){
			var res = await this.$API.bpm.bpmFromOrg.getBpmFromOrgListForSelect.get({keyword:value,orgType:'2'});
			if(res.code==200)
			{
				this.fromOrgList = res.data;
			}
		}
	}
}
</script>
